<%--<%@ page import="com.shop.service.OrderService" %>--%>
<%--<%@ page import="java.util.List" %>--%>
<%--<%@ page import="com.shop.model.Order" %>--%>
<%--<%@ page import="java.util.ArrayList" %>--%>
<%--<%@ page import="com.shop.service.CourseService" %>--%>
<%--<%@ page import="com.shop.model.Course" %>--%>
<%--<%@ page import="java.time.format.DateTimeFormatter" %>--%>
<%--<%@ page import="java.time.LocalDateTime" %>&lt;%&ndash;--%>
<%--  Created by IntelliJ IDEA.--%>
<%--  User: Administrator--%>
<%--  Date: 2025/5/30--%>
<%--  Time: 下午3:30--%>
<%--  To change this template use File | Settings | File Templates.--%>
<%--&ndash;%&gt;--%>
<%--<%@ page contentType="text/html;charset=UTF-8" language="java" %>--%>
<%--<html>--%>
<%--<head>--%>
<%--    <title>我的订单</title>--%>
<%--    <style>--%>
<%--        /* 添加一些基本的样式 */--%>
<%--        table {--%>
<%--            width: 100%;--%>
<%--            border-collapse: collapse;--%>
<%--        }--%>
<%--        th, td {--%>
<%--            border: 1px solid black;--%>
<%--            padding: 8px;--%>
<%--            text-align: left;--%>
<%--        }--%>
<%--        th {--%>
<%--            background-color: #f2f2f2;--%>
<%--        }--%>
<%--    </style>--%>
<%--</head>--%>
<%--<body>--%>
<%--<h2>我的订单</h2>--%>
<%--<%--%>
<%--    String studentId = request.getParameter("studentId");--%>
<%--    System.out.println("my_order.jsp:37: " + studentId);--%>

<%--    OrderService orderService = new OrderService();--%>
<%--    CourseService courseService = new CourseService();--%>

<%--    List<Order> orders = orderService.queryOrder(studentId);--%>

<%--    System.out.println("my_order.jsp:43: " + orders.size());--%>
<%--    List<String> coursesId = new ArrayList<>();--%>
<%--    List<Course> courses = new ArrayList<>();--%>

<%--    for (Order order : orders) {--%>
<%--        coursesId.add(order.getCoursesId());--%>
<%--    }--%>
<%--    for (String courseId : coursesId) {--%>
<%--        courses.add(courseService.searchCourse1(courseId));--%>
<%--    }--%>
<%--%>--%>
<%--<table>--%>
<%--    <tr>--%>
<%--        <th>订单Id</th>--%>
<%--        <th>用户Id</th>--%>
<%--        <th>课程名</th>--%>
<%--        <th>总价</th>--%>
<%--        <th>下单时间</th>--%>
<%--        <th>状态</th>--%>
<%--    </tr>--%>
<%--        <%--%>
<%--            for (int i =0;i<coursesId.size();i++){--%>
<%--            Course course = courses.get(i);--%>
<%--            Order order = orders.get(i);--%>

<%--            LocalDateTime dateTime = order.getOrder_date();--%>
<%--            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");--%>
<%--            String formattedDateTime = dateTime.format(formatter);--%>
<%--        %>--%>
<%--    <tr>--%>
<%--        <td><%=order.getOrderId()%></td>--%>
<%--        <td><%=order.getStudentId()%></td>--%>
<%--        <td><%=course.getCourseName()%></td>--%>
<%--        <td><%=order.getTotal_price()%></td>--%>
<%--        <td><%=formattedDateTime%></td>--%>
<%--        <td><%=order.getStatus()%></td>--%>
<%--    </tr>--%>
<%--        <%--%>
<%--            }--%>
<%--        %>--%>
<%--</table>--%>
<%--</body>--%>
<%--</html>--%>


<%@ page import="com.shop.service.OrderService" %>
<%@ page import="com.shop.model.Order" %>
<%@ page import="com.shop.service.CourseService" %>
<%@ page import="com.shop.model.Course" %>
<%@ page import="java.time.format.DateTimeFormatter" %>
<%@ page import="java.time.LocalDateTime" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.shop.service.ICourseService" %>
<%@ page import="com.shop.service.IOrderService" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title>我的订单</title>
    <style>
        :root {
            --primary-color: #4361ee;
            --secondary-color: #3f37c9;
            --light-color: #f8f9fa;
            --dark-color: #212529;
            --success-color: #4cc9f0;
            --danger-color: #f72585;
            --border-radius: 8px;
            --box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }

        body {
            background-color: #f5f7fa;
            color: var(--dark-color);
            line-height: 1.6;
            padding: 20px;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
        }

        .page-header {
            text-align: center;
            margin-bottom: 30px;
            padding-bottom: 15px;
            border-bottom: 1px solid #eee;
        }

        .page-header h2 {
            color: var(--primary-color);
            font-size: 28px;
            margin-bottom: 10px;
        }

        .orders-table {
            width: 100%;
            border-collapse: separate;
            border-spacing: 0;
            background-color: white;
            border-radius: var(--border-radius);
            overflow: hidden;
            box-shadow: var(--box-shadow);
        }

        .orders-table thead th {
            background-color: var(--primary-color);
            color: white;
            padding: 15px;
            text-align: left;
            font-weight: 600;
        }

        .orders-table tbody tr {
            transition: all 0.2s ease;
        }

        .orders-table tbody tr:nth-child(even) {
            background-color: var(--light-color);
        }

        .orders-table tbody tr:hover {
            background-color: rgba(67, 97, 238, 0.1);
        }

        .orders-table td {
            padding: 12px 15px;
            border-bottom: 1px solid #eee;
        }

        .status {
            display: inline-block;
            padding: 4px 8px;
            border-radius: 12px;
            font-size: 12px;
            font-weight: 600;
            text-transform: uppercase;
        }

        .status-paid {
            background-color: rgba(76, 201, 240, 0.1);
            color: var(--success-color);
        }

        .status-pending {
            background-color: rgba(247, 37, 133, 0.1);
            color: var(--danger-color);
        }

        .price {
            font-weight: 600;
            color: var(--primary-color);
        }

        .no-orders {
            text-align: center;
            padding: 40px;
            color: #777;
        }

        @media (max-width: 768px) {
            .orders-table {
                display: block;
                overflow-x: auto;
            }

            .page-header h2 {
                font-size: 24px;
            }
        }
    </style>
</head>
<body>
<div class="container">
    <div class="page-header">
        <h2>我的订单</h2>
        <p>查看您的课程购买记录</p>
    </div>

    <%
        String studentId = request.getParameter("studentId");
        System.out.println("my_order.jsp:37: " + studentId);

        IOrderService iorderService = new OrderService();
        ICourseService icourseService = new CourseService();

        List<Order> orders = iorderService.queryOrder(studentId);

        System.out.println("my_order.jsp:43: " + orders.size());
        List<String> coursesId = new ArrayList<>();
        List<Course> courses = new ArrayList<>();

        for (Order order : orders) {
            coursesId.add(order.getCoursesId());
        }
        for (String courseId : coursesId) {
            courses.add(icourseService.searchCourse1(courseId));
        }
    %>

    <% if (orders.isEmpty()) { %>
    <div class="no-orders">
        <p>您还没有任何订单记录</p>
    </div>
    <% } else { %>
    <table class="orders-table">
        <thead>
        <tr>
            <th>订单编号</th>
            <th>课程名称</th>
            <th>金额</th>
            <th>下单时间</th>
            <th>状态</th>
        </tr>
        </thead>
        <tbody>
        <%
            for (int i = 0; i < coursesId.size(); i++) {
                Course course = courses.get(i);
                Order order = orders.get(i);

                LocalDateTime dateTime = order.getOrder_date();
                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
                String formattedDateTime = dateTime.format(formatter);

                // 根据状态设置样式类
                String statusClass = "status-" + (order.getStatus().toLowerCase().contains("完成") ? "paid" : "pending");
        %>
        <tr>
            <td>#<%=order.getOrderId()%></td>
            <td><%=course.getCourseName()%></td>
            <td class="price">¥<%=order.getTotal_price()%></td>
            <td><%=formattedDateTime%></td>
            <td><span class="status <%=statusClass%>"><%=order.getStatus()%></span></td>
        </tr>
        <%
            }
        %>
        </tbody>
    </table>
    <% } %>
</div>
</body>
</html>